package AbstractTransaction

import (
	"PaySalary/DataBase"
	"Paysalary/Model"
	"fmt"
	"log"
	"strconv"
)

type ChangeTransaction interface {
	Change(employee *Model.Employee)
}

type ChangeEmployeeTransaction struct {
	itsEmpid int
	ChangeTransaction
}

func (transaction *ChangeEmployeeTransaction) SetEmpid(empid int) {
	transaction.itsEmpid = empid
}

func (transaction *ChangeEmployeeTransaction) Execute() {
	e := DataBase.TheInstance.GetEmployee(transaction.itsEmpid)

	if e == nil {
		err := fmt.Errorf(DataBase.PayrollExceptionMessage.EmployeeNotExist + strconv.Itoa(transaction.itsEmpid))
		log.Println(err.Error())
		return
	}

	transaction.Change(e)
}
